<template>
  <div class="bgwrap">
    <bg-canvas></bg-canvas>
    <div id="area">
      <h1>进思学院课程管理系统</h1>
      <el-form class="formWrap">
        <el-form-item>
          <el-input placeholder="用户名"
                    v-model="username"
                    class="input-with-select">
            <el-button slot="prepend"
                       icon="el-icon-user-solid"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input placeholder="密码"
                    v-model="password"
                    class="input-with-select">
            <el-button slot="prepend"
                       icon="el-icon-s-goods"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item class="veri_wrap">
          <el-input placeholder="验证码"
                    v-model="veri"
                    class="input-with">
            <el-button slot="prepend"
                       icon="el-icon-info"></el-button>
          </el-input>
          <!-- 验证码组件 -->
          <div class="vericon">
            <veri></veri>
          </div>
        </el-form-item>
      </el-form>
      <div class="btnwrap">
        <el-button type="primary">忘记密码</el-button>
        <el-button @click="login"
                   type="success">登录</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import bgCanvas from './bgCanvas.vue'
import veri from './veri.vue'
import { checkVeri, LoginApi,Log } from '../../api/login'
import { userInfo } from '../../api/common'
export default {
  name: 'Ljfvue2011Index',
  components: {
    bgCanvas,
    veri
  },
  created () {

  },
  data () {
    return {
      username: "",
      veri: "", //验证码
      password: ""
    };
  },

  mounted () {
    console.log(123)
    Log({userName:"fff",userPwd:"123456"}).then(res=>{
        console.log(res)
    })
  },

  methods: {
    async login () { //登录方法
      console.log(this.veri)
      var veriRes = await checkVeri(this.veri);
      console.log(veriRes)
      if (veriRes.data.success) {
        // 登录
        var loginRes = await LoginApi({
          userName: this.username,
          password: this.password
        });
        console.log(loginRes)
        if (loginRes.data.success) {
          // 登录成功后 获取用户信息
          var userRes = await userInfo();
          console.log(userRes)
          this.$store.commit("changeUser", userRes.data)
          localStorage.userInfo = JSON.stringify(userRes.data)
          this.$store.commit("changeData", []);//默认面包屑导航 只有首页
          this.$router.replace({ name: "Home" })
        } else {
          this.$message(loginRes.data.err)
        }
      } else {
        alert("验证码错误")
      }
    }
  },
};
</script>

<style lang="less" >
@import url("../../assets/common.less");
.cc {
  color: @color;
  background: @bg;
  .border(2px);
  .sw();
}
.bgwrap {
  background: rgba(12, 24, 84);
}
.el-form-item input {
  color: white !important;
}
#area {
  width: 50%;
  height: 500px;
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  // background: white;
  h1 {
    color: white;
    font-size: 30px;
    font-family: "黑体";
    text-align: center;
  }
  .formWrap {
    width: 70%;
    margin: 20px auto;
    height: 250px;
    .el-input {
      margin-top: 20px;
      button {
        border-radius: 0;
        background: rgba(12, 24, 84);
      }
      input {
        background: rgba(12, 24, 84);
      }
    }
    .input-with {
      width: 60%;
    }
  }
  .btnwrap {
    width: 80%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
  }
}
.veri_wrap {
  .el-form-item__content {
    display: flex;
    .vericon {
      height: 40px;
      padding-top: 20px;
      padding-left: 20px;
      box-sizing: border-box;
    }
  }
}
</style>